// Copyright (C) 2016 All rights reserved.
// Author: liufeng11@letv.com (Liu Feng)
// Description:

#include "MyFontFeatureExtractor.h"
#include "HaarFontFeatureExtractor.h"
#include "HogFontFeatureExtractor.h"
#include "MySimilarity.h"
#include "SimilarCharacter.h"
#include <stdio.h>

void test1() {
  unsigned char data[32*32] = {0};

  MyFontFeatureExtractor ffe;
  Similarity si;
  std::vector<double> v1 = ffe(0x5df1);
  std::vector<double> v2 = ffe(0x5df2);

  printf("sim: %f\n", si(v1, v2));

  v1 = ffe(0x5df1);
  v2 = ffe(0x4e38);
  printf("sim: %f\n", si(v1, v2));
}

void test2() {
  while(true) {
    unsigned int charCode = 0;
    scanf("%x", &charCode);
    printf("%04x\n", charCode);

    HogFontFeatureExtractor ffe;
    Similarity si;
    SimilarCharacter<10> sc(&si, &ffe);
    std::vector<mypair> r = sc(charCode);
    printf("size = %d\n", r.size());

    for (size_t i = 0; i < r.size(); ++i) {
      printf("%04x = %f\n", r[i].second, r[i].first);
    }
  }
}

void WriteFeature(FILE* fp, unsigned int charCode, const std::vector<double> &f) {
  fprintf(fp, "%04x ", charCode);
  if (f.empty()) {
    fprintf(fp, "\n");
    return;
  }
  
  fprintf(fp, "%.15lf", f[0]);
  
  for (size_t i = 1; i < f.size(); ++i) {
    fprintf(fp, ",%f", f[i]);
  }
  
  fprintf(fp, "\n");
  return;
}
void ExtractFeature() {
  HogFontFeatureExtractor ffe;
  FILE *fp = fopen("features.dat", "w");
  
  unsigned int iter = 0x4e00;
  unsigned int last = 0x9fa5;

  while(iter != last) {
    std::vector<double> f;
    if (ffe.GetFeature(iter, &f)) {
      WriteFeature(fp, iter, f);
    }
    else {
    }
    ++iter;
  }
  fclose(fp);
}
int main() {

  ExtractFeature();
  return 0;
}
